const path = require('path');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
  publicPath: './',
  lintOnSave: false,
  pages: {
    index: {
      entry: 'examples/main.js',
      template: 'public/index.html',
      filename: 'index.html',
    },
  },
  // Webpack 的合并配置，会通过 webpack-merge 合并到配置中
  configureWebpack: config => {
    // 为文件夹取别名
    config.resolve.alias['@'] = path.resolve(__dirname, './examples');
    config.resolve.alias['@p'] = path.resolve(__dirname, './packages');
    // 生产环境中移除 debugger 和 console
    config.optimization.minimizer[0].options.terserOptions.compress.drop_console =
      isProd;
    config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger =
      isProd;
  },
  chainWebpack: config => {
    config.module
      .rule('js')
      .include.add(path.resolve(__dirname, 'packages'))
      .end()
      .use('babel')
      .loader('babel-loader')
      .tap(options => {
        return options;
      });
  },
  devServer: {
    overlay: {
      warnings: true,
      errors: false,
    },
    https: false,
    open: false,
    disableHostCheck: true,
  },
};
